feat(aws-lambda-microvm): refresh identity on run hook - #19781
feat(aws-lambda-microvm): refresh identity on run hook#19781litianningdatadog wants to merge 4 commits into
Conversation
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
|
Dependency direction analysis📈 Existing violations got worse10 pre-existing violation(s) increased in severity (e.g. their target became more depended-on, or got pulled into an import cycle), though the edge itself isn't new: Show violations that got worse (showing 5 of 10 highest severity)
|
BenchmarksBenchmark execution time: 2026-08-20 11:54:47 Comparing candidate commit 621c074 in PR branch Found 0 performance improvements and 4 performance regressions! Performance is the same for 382 metrics, 9 unstable metrics.
|
There was a problem hiding this comment.
Pull request overview
This PR activates “identity refresh” for AWS Lambda MicroVM restores by hooking the earliest shared platform signal (POST /aws/lambda-microvms/runtime/v1/run) into the existing core.WEB_REQUEST_STARTING event, ensuring runtime- and identity-bound components get refreshed once per process in MicroVM environments.
Changes:
- Add MicroVM
/runhook matching + once-per-process identity refresh registration toddtrace.internal.runtime. - Expand runtime-id tests to cover exact hook matching, ordering (pre-root-span), and concurrency behavior.
- Update web framework tests to use the real MicroVM hook path constant and add a release note.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| ddtrace/internal/runtime/init.py | Registers a MicroVM-only WEB_REQUEST_STARTING listener to refresh identity once when the exact /run hook is observed. |
| tests/tracer/runtime/test_runtime_id.py | Adds subprocess tests for hook matching, ordering vs root span creation, concurrency safety, and non-MicroVM no-op behavior. |
| tests/contrib/asgi/test_microvm_identity_refresh.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions in ASGI middleware tests. |
| tests/contrib/bottle/test_microvm_identity_refresh.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions in Bottle integration tests. |
| tests/contrib/cherrypy/test_microvm_identity_refresh.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions in CherryPy integration tests. |
| tests/contrib/django/test_microvm_identity_refresh.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions in Django integration tests. |
| tests/contrib/falcon/test_microvm_identity_refresh.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions in Falcon integration tests. |
| tests/contrib/flask/test_microvm_identity_refresh.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions (including WSGI environ) in Flask integration tests. |
| tests/contrib/http_server/test_microvm_identity_refresh.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions in http.server integration tests. |
| tests/contrib/molten/test_microvm_identity_refresh.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions in Molten integration tests. |
| tests/contrib/pyramid/test_microvm_identity_refresh.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions in Pyramid integration tests (including tracing-disabled path). |
| tests/contrib/sanic/test_sanic.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions in Sanic integration tests. |
| tests/contrib/tornado/test_microvm_identity_refresh.py | Uses MICROVM_RUN_HOOK_PATH for request-start dispatch assertions in Tornado integration tests. |
| releasenotes/notes/aws-lambda-microvm-identity-refresh-3a672cd6bcbad16d.yaml | Documents MicroVM-only stable identifier regeneration behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| import threading | ||
| import typing as t | ||
| import uuid | ||
| import weakref | ||
|
|
||
| from ddtrace.internal import core | ||
| from ddtrace.internal import forksafe |
Some runtimes can restore a process from a snapshot without creating a real fork. Reusing the fork hook there would give the process a fresh runtime id, but it would also record fake parent and ancestor lineage. Add a direct refresh_identity() path for that case. Runtime-id subscribers are weakly held and isolated from each other so long-lived components can rebuild cached identity state without leaking instances or breaking the refresh caller.
The MicroVM /run hook needs to be observed before a web root span reads process identity, but Python has no single HTTP server substrate across WSGI, ASGI, and framework integrations. Introduce a shared core event that web integrations emit once method and path are available, before root span creation. The event is deliberately generic here; it does not know about MicroVMs or refresh runtime ids yet.
b9a5154 to
c992c42
Compare
Rotating the runtime id is not enough by itself. Several long-lived components bake runtime or Remote Config client identity into native clients, workers, upload metadata, or tag caches. Have those components subscribe to explicit identity refreshes and rebuild only the state that captures those ids. Fork-specific cleanup remains on the existing fork hooks so this path does not drop buffers or invent fork lineage.
c992c42 to
d424d55
Compare
03c4230 to
55f826c
Compare
AWS Lambda MicroVM instances restored from the same image start with the same in-memory runtime id and Remote Config client id. The platform's /run lifecycle request is the earliest common signal that a restored instance is becoming active. Register the web request listener only inside MicroVM images, match the fixed POST /run hook, and refresh identity once per process. Stacked web layers can observe the same request without rotating identity more than once.
55f826c to
621c074
Compare
230002b to
8faa264
Compare
|
Closed as we switched to smaller PRs with vertical changes |
Description
AWS Lambda MicroVM instances created from the same image start with the same in-memory runtime id and Remote Config client id. The platform
POST /aws/lambda-microvms/runtime/v1/runrequest is the earliest shared signal that a restored instance is becoming active.This registers the web request listener only inside MicroVM images, matches the fixed
/runhook, and refreshes identity once per process. The once-only guard handles stacked web layers observing the same platform request.Testing
Added hook matcher coverage for exact match, ignored requests, listener registration outside MicroVMs, root-span ordering, and concurrent observations. Updated web event tests to use the real MicroVM hook path.
Risks
Medium. This is the PR that activates identity refresh from request dispatch, but only when
AWS_LAMBDA_MICROVM_IMAGE_ARNis present and only for the fixed platform hook.Additional Notes
Stacked on #19780.